﻿/*
 * 版 本 v1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.17
 */
var refreshGirdData; // 更新数据
var selectedRow;

var acceptClick;
var dialogClose;

var bootstrap = function ($, learun) {
    "use strict";
    var page = {
        init: function () {
            page.initGrid();
            page.bind();
        },
        bind: function () {
            // 搜索框初始化
            $('#txt_Keyword').on("keypress", function (e) {
                if (event.keyCode == "13") {
                    var $this = $(this);
                    var keyword = $this.val();
                    page.search({keyword: keyword});
                }
            });
            // 查询
            $('#btn_Search').on('click', function () {
                var keyword = $('#txt_Keyword').val();
                page.search({keyword: keyword});
            });
            // 刷新
            $('#lr_refresh').on('click', function () {
                location.reload();
            });
        },
        initGrid: function () {
            $('#gridtable').jfGrid({
                url: config.base_server() + 'stdhotels/list?access_token=' + config.getToken().access_token,
                headData: [
                    {label: "省份", name: "provinceName", width: 100, align: "left", isMerge: true},
                    {label: "城市", name: "cityName", width: 120, align: "left", isMerge: true},
                    {
                        label: "住宿费标准", name: "住宿费标准", width: 240, align: 'center',
                        children: [
                            {
                                label: "部级", name: "level1Standard", width: 80, align: "center"
                            },
                            {
                                label: "司局级", name: "level2Standard", width: 80, align: "center"
                            },
                            {
                                label: "其他人员", name: "level3Standard", width: 80, align: "center"
                            }
                        ]
                    },
                    {
                        label: "旺季浮动标准", name: "旺季浮动标准", width: 360, align: 'center',
                        children: [
                            {label: "旺季月份", name: "highSeason", width: 120, align: "center"},
                            {
                                label: "部级", name: "level1Highstandard", width: 80, align: "center"
                            },
                            {
                                label: "司局级", name: "level2Highstandard", width: 80, align: "center"
                            },
                            {
                                label: "其他人员", name: "level3Highstandard", width: 80, align: "center"
                            }
                        ]
                    }
                ],
                dblclick: function (row) {
                    selectedRow = $('#gridtable').jfGridGet('rowdata');
                    var keyValue = row;
                    if (!!row.cityName) {
                        parent.$(".layui-layer-btn0")[1].click();
                    }
                    //关闭layer弹出层
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                },
                isTree: false,
                mainId: 'id'
            });
            page.search();
        },
        search: function (param) {
            $('#gridtable').jfGridSet('reload', param);
        }
    };

    // 保存数据后回调刷新
    refreshGirdData = function () {
        page.search();
    }

    //确认按钮
    acceptClick = function (callback) {
        var row = $('#gridtable').jfGridGet('rowdata');
        if (row.cityName) {
            var datajson = {
                cityId: row.cityId,
                cityName: row.cityName,
            }
            callback(null, datajson);
            dialogClose();
        } else {
            learun.alert.warning('请选择城市！');
        }
    }

    dialogClose = function () {
        try {
            var index = top.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            var $IsdialogClose = top.$("#layui-layer" + index).find('.layui-layer-btn').find("#IsdialogClose");
            var IsClose = $IsdialogClose.is(":checked");
            if ($IsdialogClose.length == 0) {
                IsClose = true;
            }
            if (IsClose) {
                top.layer.close(index);
            } else {
                location.reload();
            }
        } catch (e) {
            alert(e);
        }
    }

    page.init();
}


